<template>
  <view class="site-wraps">
    <view class="site-swiper"
      ><u-swiper
        class="site-swiper"
        :list="bannerArr"
        indicator
        :indicator-mode="'number'"
        :indicator-color="'#ffffff'"
        :indicator-active-color="'#007aff'"
      ></u-swiper>
    </view>

    <!-- 场馆介绍 -->
    <view class="site-info">
      <view class="info-top">
        <view class="site-title">{{ siteInfo.site_name }}</view>
        <view class="site-toggle">
          <image class="toggle-btn" src="@/static/img/toggle.png"></image>
          <view class="txt">切换场馆</view>
        </view>
      </view>
      <view class="info-bottom">
        <view class="address">{{ siteInfo.city }}市{{ siteInfo.address }}</view>
        <div class="right">
          <image
            class="nav"
            @click="goToLocation"
            src="@/static/img/nav.png"
          ></image>
          <image
            class="phone"
            @click="callPhoneNumber()"
            src="@/static/img/phone.png"
          ></image>
        </div>
      </view>
    </view>

    <view class="tag-wrap">
      <view class="times-box">
        <view
          :class="['status', siteInfo.status == 'OPEN' ? 'status-green' : '']"
          >{{ siteInfo.status == 'OPEN' ? '开放中' : '关闭中' }}</view
        >
        <view class="times">{{ siteInfo.open_time }}</view>
      </view>
      <view class="card-wrap">
        <view class="capacity">{{ siteInfo.capacity }}人</view>
        <!-- <view class="card-box" v-for="item in siteInfo.key_words"> -->
        <view class="card-box">
          <view class="every">室内游泳</view>
          <view class="every">深水区</view>
          <view class="every">浅水区</view>
          <view class="every">儿童游泳</view>
          <view class="every">游泳培训</view>
          <view class="every">每日消毒</view>
        </view>
      </view>
    </view>

    <!-- 泳票列表 -->
    <view class="content">
      <!-- <view class="content-title">
        <view class="content-line"></view>
        <text class="index-title">泳票</text>
      </view> -->
      <view class="content-inner">
        <view
          class="inner-item"
          v-for="(item, index) in titckTemplates"
          :key="index"
        >
          <view class="item-left">
            <image :src="item.image_url" />
          </view>
          <view class="item-content">
            <view class="item-title">{{ item.template_title }}</view>
            <!-- <view class="item-desc">{{ item.template_desc }}</view> -->
            <view class="center-box">
              <view class="ticket_times">{{
                item.ticket_times == 1 ? '单次卡' : '多次卡'
              }}</view>
              <view class="line"> | </view>
              <view class="one_day">{{
                item.one_day == 1 ? '指定日期' : '不指定'
              }}</view>
            </view>

            <!-- <view class="item-date">有限期：{{ item.start_date }} 至 {{ item.end_date }}</view>
            <view class="item-time">时段：{{ item.start_time }}-{{ item.end_time }}</view> -->

            <view class="price-wrap">
              <view class="item-price-box">
                <text class="item-unit">￥</text>
                <text class="item-price">{{ item.ticket_price / 100 }}</text>
                <text class="item-qi">起</text>
              </view>
              <view class="pay-wrap">
                <view
                :class="['pay-btn',item.one_day == 1 ? '' : 'free-btn']"
                 @tap="handleBuy(item.template_id)">{{
                  item.one_day == 1 ? '抢购' : '领取'
                }}</view>
              </view>
            </view>
          </view>
          <!-- <view class="pay-wrap">
            <view class="pay-btn" @tap="handleBuy">购买</view>
          </view> -->
        </view>
      </view>
    </view>

    <!-- 场馆列表   -->
    <!-- <view class="content">
      <view class="content-title">
        <view class="content-line"></view>
        <text class="index-title">场馆</text>
      </view>
      <view class="content-inner">
        <view
          class="inner-item index-venue-item"
          v-for="(item, index) in siteArr"
          :key="index"
        >
          <view class="item-left">
            <image
              src="https://pic4.58cdn.com.cn/nowater/lbgfe/image/n_v3d1250036fb064b10b09797f12dba27b7.png"
            />
          </view>
          <view class="item-content">
            <view class="item-title">{{ item.title }}</view>
            <view class="item-desc">{{ item.desc }}</view>
          </view>
        </view>
      </view>
    </view> -->
  </view>
</template>

<script>
import { request, requestData } from '@/utils/http.js'

export default {
  data() {
    return {
      site_code: '',
      titckTemplates: [],
      bannerArr: [],
      titckArr: [],
      // siteArr: [
      //   {
      //     img: 'https://ya30images.hbwlife.com/wxmpadmin/allCard_1.png',
      //     title: '场馆1',
      //     desc: '场馆的内容描述',
      //   },
      //   {
      //     img: 'https://ya30images.hbwlife.com/wxmpadmin/allCard_1.png',
      //     title: '场馆2',
      //     desc: '场馆的内容描述',
      //   },
      // ],
      // latitude: '',
      // longitude: '',
      // name: '',
      // address: '',
      siteInfo: {},
    }
  },
  mounted() {
    this.initSiteInfo()
  },
  methods: {
    handleBuy(id) {
      uni.navigateTo({
        url: `/pagesB/titckDetail/titckDetail?id=${id}`,
      })
    },
    //init siteInfo  banner
    initSiteInfo(str) {
      request('/common/site/info', {
        site_code: '17001',
        with_images: 1,
      })
        .then((res) => {
          this.siteInfo = res.datas
          let bannerPic = res.datas.images
          this.bannerArr.push(
            bannerPic.logo1,
            bannerPic.logo2,
            bannerPic.logo3,
            bannerPic.logo4,
            bannerPic.logo5,
            bannerPic.logo6,
            bannerPic.logo7,
            bannerPic.logo8,
            bannerPic.logo9
          )
          this.site_code = res.datas.images.site_code
          this.templateList(this.site_code)
        })
        .catch((err) => {
          console.log(err)
        })
    },

    //泳票列表
    templateList(site_code) {
      request('/common/ticket/template/list', {
        user_id: uni.getStorageSync('user_id'),
        site_code: site_code,
      })
        .then((res) => {
          console.log(res)
          this.titckTemplates = res?.datas?.templates
        })
        .catch((err) => {
          console.log(err)
        })
    },
    //init ticket template
    // initTicketInfo(str) {
    //   request('/common/ticket/template/info', {
    //     template_id: '17001',
    //     with_images: 1,
    //   })
    //     .then((res) => {
    //       this.siteInfo = res.datas
    //       let bannerPic = res.datas.images
    //       this.bannerArr.push(
    //         bannerPic.logo1,
    //         bannerPic.logo2,
    //         bannerPic.logo3,
    //         bannerPic.logo4,
    //         bannerPic.logo5,
    //         bannerPic.logo6,
    //         bannerPic.logo7,
    //         bannerPic.logo8,
    //         bannerPic.logo9
    //       )
    //     })
    //     .catch((err) => {
    //       console.log(err)
    //     })
    // },
    goToLocation() {
      uni.openLocation({
        latitude: this.siteInfo.latitude,
        longitude: this.siteInfo.longitude,
        name: this.siteInfo.site_name,
        address: this.siteInfo.city + '市' + this.siteInfo.address,
        success() {
          console.log('导航成功')
        },
        fail(err) {
          console.error('导航失败', err)
          uni.showToast({
            title: '导航失败！',
            icon: 'none',
          })
        },
      })
    },
    callPhoneNumber() {
      uni.makePhoneCall({
        phoneNumber: this.siteInfo.phone,
        success: () => {
          console.log('拨打成功！')
        },
        fail: () => {
          console.error('拨打失败！')
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.site-wraps {
  width: 100%;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
  // background: $global-background-grey;
  padding-top: 0;
  margin-top: 0;
}

.site-swiper {
  height: 460rpx !important;
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* 更改u-swiper样式 */
::v-deep .u-swiper {
  height: 100% !important;
}

::v-deep .u-swiper__wrapper.data-v-6b019429 {
  height: 100% !important;
}

::v-deep .u-swiper__wrapper__item__wrapper__image.data-v-6b019429 {
  height: 100% !important;
}

::v-deep .u-swiper__indicator data-v-6b019429 {
  bottom: 40rpx !important;
}

::v-deep .u-swiper__indicator-dot {
  width: 58rpx !important;
  height: 58rpx !important;
}

/* info */
.site-info {
  width: 94%;
  height: 200rpx;
  border-radius: 10rpx;
  background: #fff;
  margin: 0 auto;
  margin-top: -15rpx;
  z-index: 999;
  position: relative;
  opacity: 1;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.25);
  padding: 0 20rpx;
  box-sizing: border-box;
}
.site-info .info-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed #e4e1e1;
  height: 100rpx;
  line-height: 1;
}

.site-toggle {
  padding: 10rpx;
  border-radius: 15rpx 0 0 15rpx;
  position: absolute;
  right: 0;
  width: auto;
  height: 40rpx;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 22rpx;
  // background: #f5f2f2;
  color: #6e6d6d;
}
.site-toggle .toggle-btn {
  width: 36rpx;
  height: 36rpx;
  margin-right: 15rpx;
}
.site-info .info-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100rpx;
  line-height: 1;
}
.info-bottom .address {
  font-size: 28rpx;
}
.info-bottom .right {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.info-bottom .right image {
  width: 40rpx;
  height: 40rpx;
  padding: 0 30rpx;
}
.info-bottom .right .nav {
  border-right: 1px dashed #e4e1e1;
}
.info-bottom .right .phone {
  padding-right: 0;
}
/*  */
.tag-wrap {
  box-sizing: border-box;
  padding: 0 20rpx;
  margin-top: 50rpx;
  font-size: 28rpx;
}
.times-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.times-box .status {
  color: #988b4b;
  margin-right: 20rpx;
}
.times-box .status-green {
  color: #4cd964;
}
.card-wrap {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 22rpx;
  margin-top: 30rpx;
}

.card-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.every,
.capacity {
  margin-right: 5rpx;
  padding: 8rpx;
  border-radius: 10rpx;
  color: #848181;
  background: #eeefee;
}
.capacity {
  color: #ff9800;
}
/*  */
.content {
  width: 100%;
  height: auto;
  min-height: 200rpx;
  box-sizing: border-box;
  padding: 0 20rpx;
  margin-top: 50rpx;
  background: $global-background-grey;
}

.content-title {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  box-sizing: border-box;
  padding: 20rpx 0;
}

.content-line {
  width: 6rpx;
  height: 30rpx;
  background-color: $global-color-golden;
  border-radius: 2px;
  box-sizing: border-box;
}

.index-title {
  // font-weight: bold;
  color: $global-title-color-bold;
  font-size: 32rpx;
  margin-left: 22rpx;
  box-sizing: border-box;
}

.index-title-icon-wrap {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 48rpx;
  box-sizing: border-box;
  background: #fff;
  padding: 20rpx;
}

.index-title-icon-item {
  width: 93rpx;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  box-sizing: border-box;
}

.index-title-icon {
  width: 93rpx;
  height: 93rpx;
  background-color: #fdfbeb;
  border-radius: 50%;
  font-size: 28rpx;
  color: $global-color-golden;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.index-title-icon-item-active .index-title-icon {
  background-color: $global-color-golden;
  color: #fff;
  box-sizing: border-box;
}

.index-title-icons {
  width: 64rpx;
  height: 64rpx;
}

.index-title-icon-txt {
  margin-top: 24rpx;
  color: #010101;
  font-size: 28rpx;
  box-sizing: border-box;
}

.content-inner {
  width: 100%;
  height: auto;
  overflow: hidden;
  box-sizing: border-box;
  padding-bottom: 34rpx;
  margin-top: 20rpx;
}

.inner-item {
  width: 100%;
  height: auto;
  padding: 10rpx;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20rpx;
  background: #fff;
}

.item-left {
  width: 148rpx;
  height: auto;
}

.item-left image {
  width: 148rpx;
  height: 148rpx;
  box-sizing: border-box;
  object-fit: contain;
  border-radius: 12rpx;
}

.item-content {
  flex: 1;
  padding: 20rpx 0 20rpx 20rpx;
}

.center-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-top: 15rpx;
  color: $global-fontcolor-black;
}
.center-box .ticket_times,
.one_day {
  box-sizing: border-box;
  font-size: 28rpx;
}
.center-box .line {
  margin: 0 20rpx;
  width: 2rpx;
  height: auto;
  color: #969698;
}

.item-title {
  color: $global-title-color-bold;
  box-sizing: border-box;
}

// .item-desc {
//   color: $global-fontcolor-black;
//   margin-top: 8rpx;
//   box-sizing: border-box;
// }
.item-date {
  color: $global-fontcolor-black;
  margin-top: 8rpx;
  box-sizing: border-box;
  font-size: 28rpx;
}
.item-time {
  color: $global-fontcolor-black;
  margin-top: 8rpx;
  box-sizing: border-box;
  font-size: 28rpx;
}

.price-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15rpx;
}
.item-price-box {
  margin-top: 8rpx;
  box-sizing: border-box;
  color: #dd524d;
}
.item-unit {
  font-size: 24rpx;
}
.item-price {
  margin-left: 5rpx;
  font-size: 32rpx;
}
.item-qi {
  margin-left: 20rpx;
  font-size: 24rpx;
}
.pay-wrap {
  width: 133rpx;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pay-btn {
  width: auto;
  height: auto;
  padding: 15rpx 30rpx;
  border-radius: 11rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  background: #e26f21;
  box-sizing: border-box;
  font-size: 28rpx;
}
.free-btn{
  background: #d5ad57;
  
}

.index-venue-item {
  align-items: flex-start;
}

.index-grid-wrap {
  width: 100%;
  height: auto;
  display: grid;
  gap: 20rpx;
  grid-template-columns: 1fr 1fr 1fr;
  /* 两列，每列宽度相等 */
  grid-template-rows: auto;
  /* 自动高度 */
  margin-top: 20rpx;
}

.index-content-item {
  width: 1fr;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}

.index-content-item image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 20rpx;
}

.index-grid-title {
  color: #010101;
  margin-top: 10rpx;
  font-weight: 500;
}

.index-venue-item .item-left image {
  width: 100%;
}
</style>
